package com.gitee.huxing.course.conc.task;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.task
 * @ClassName: TaskService01Impl
 * @Author: huxing
 * @DateTime: 2021-08-25 下午4:58
 */
public class TaskThreadPool08 extends AbstractTaskThreadPool{

    public static void main(String[] args) throws InterruptedException{
        new TaskThreadPool08().task();
    }

    @Override
    public int threadTask() {
        final int[] result = new int[1];
        // 阻塞队列处理
        BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<>(1);
        new Thread(() -> {
            try {
                result[0] = CourseTask.sum();
                blockingDeque.put(result[0]);
            } catch (Exception ex){
                ex.printStackTrace();
            }
        }).start();
        //  线程处理
        try {
            blockingDeque.take();
        } catch (Exception ex){
            ex.printStackTrace();
        }
        return result[0];
    }
}
